﻿using System;

namespace Transformable_Engine_v2.Engine.Global
{
    public static class Log
    {
        public enum LogType
        {
            Console,
        }

        public enum Severity
        {
            Debug,
            Info,
            Error,
            Critical
        }

        public static Severity LogSeverity { get; set; }
        public static LogType LogTarget { get; set; }
        public static bool IsActive { get; set; }

        /// <summary>
        /// For thread safe logging
        /// </summary>
        private static object _threadable = new object();

        public static void LogInfo(string message)
        {
            LogMessage(message, Severity.Info, ConsoleColor.Blue);
        }
        public static void LogDebug(string message)
        {
            LogMessage(message, Severity.Debug, ConsoleColor.DarkCyan);
        }
        public static void LogError(string message)
        {
            LogMessage(message, Severity.Error, ConsoleColor.Red);
        }
        public static void LogCritical(string message)
        {
            LogMessage(message, Severity.Critical, ConsoleColor.Yellow);
        }

        static void LogMessage(string message, Severity severity, ConsoleColor messageHeaderColor)
        {
            lock(_threadable)
            {
                if (severity >= LogSeverity)
                {
                    switch (LogTarget)
                    {
                        case LogType.Console:
                            Console.ForegroundColor = messageHeaderColor;
                            Console.Write("[{0}] - {1}", DateTime.Now.ToString("hh:mm:ss"), severity);
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine(" > {0}", message);
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }
    }
}